﻿using BLL;
using DAL.Gonggong;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace WebAPIUI.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class KangController : ControllerBase
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        private readonly KangBLL bll;

        public KangController(KangBLL bll)
        {
            this.bll = bll;
        }
        /// <summary>
        /// 康复新增
        /// </summary>
        /// <param name="info">康复类</param>
        /// <returns></returns>
        [HttpPost]
        public int Add(Kang info)
        {
            try
            {
                return bll.Add(info);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 显示+查询+分页
        /// </summary>
        /// <param name="name">食谱标题</param>
        /// <param name="pageindex">当前页</param>
        /// <param name="pagesize">每页多少条</param>
        /// <returns></returns>
        [HttpGet]
        public Fenye<Kang> Show(string? name, int pageindex = 1, int pagesize = 2)
        {
            try
            {

                return bll.Show(name, pageindex, pagesize);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        [HttpDelete]
        public int Delete(int id)
        {
            try
            {
                return bll.Delete(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 修改状态
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns></returns>
        [HttpDelete]
        public int UpdByState(int id)
        {
            try
            {
                return bll.UpdByState(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
